﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using BindableDataGrid.Data;
using RSERV.Web.Domain;

namespace RSERV.Pages
{
    public partial class Home : Page
    {
        private TableInfoService.TableInformationSoapClient tiser;
        public Home()
        {
            InitializeComponent();
            tiser = new TableInfoService.TableInformationSoapClient();
            label1.Content = InstanceSettings.connection;
            setTables();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void setTables()
        {
            tiser.getTableNamesCompleted += new EventHandler<TableInfoService.getTableNamesCompletedEventArgs>(tiser_getTableNamesCompleted);
            tiser.getTableNamesAsync();
        }

        void tiser_getTableNamesCompleted(object sender, TableInfoService.getTableNamesCompletedEventArgs e)
        {
            listBox1.ItemsSource = e.Result;
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            tiser.getTableCompleted += new EventHandler<TableInfoService.getTableCompletedEventArgs>(tiser_getTableCompleted);
            tiser.getTableAsync(e.ToString());
        }

        void tiser_getTableCompleted(object sender, TableInfoService.getTableCompletedEventArgs e)
        {
            grid1.ItemsSource = e.Result.Any;
            
            //DataSet ds = new DataSet("myDSet");
            ////ds.Tables = e.Result;
            //myBindableDG.DataSource = ds;
            //myBindableDG.DataBind();
        }

    }
}
